package com.yamvc.mvc.model
{
	import flash.events.EventDispatcher;

	public class Model extends EventDispatcher
	{
		private var _proxies:Object = new Object();
		private static var _instance:Model;
		public static function get instance():Model{
			if(_instance==null) _instance = new Model();
			return _instance;
		}
		
		public function Model(){
			super();
			if(_instance!=null) throw new Error("Singleton error!!");
		}
		
		// TODO change proxy:* to proxy:IProxy when IProxy will be created.
		public function registerProxy(proxyName:String,proxy:*):void{
			if(_proxies[proxyName]!=null){
				if(_proxies[proxyName].toString()==proxy.toString()) return;
			}
			_proxies[proxyName] = proxy;
		}
		
		public function retreaveProxy(proxyName:String):*{
			if(_proxies[proxyName]==null||_proxies[proxyName]==undefined) throw new Error("No proxy registered error. Proxy with name "+proxyName+" not found. register it before use");
			return _proxies[proxyName];
		}
	}
}